from appium import webdriver
import time

# 设置终端参数项
from appium.webdriver.common.touch_action import TouchAction

desired_caps = {
    'platformName': 'Android',
    'platformVersion': '10',
    'deviceName': 'xxx',
    'appPackage': 'lnwlztb.study',
    'appActivity': '.activity.SplashActivity',
    'noReset': True
}

# 发送指令给到appium server
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
# 获取屏幕的width和height

size = driver.get_window_size()
width = size['width']
height = size['height']


# 向上滑
def swipeUp(driver, t=1000, n=1):
    global width
    global height
    """向上屏幕滑动"""
    x1 = size["width"] * 0.5  # x坐标
    y1 = size["height"] * 0.75  # 起点 y坐标
    y2 = size["height"] * 0.25  # 终点 y 坐标
    for i in range(n):
        driver.swipe(x1, y1, x1, y2, t)


# 向下滑
def swipeDown(driver, t=1000, n=2):
    """向下屏幕滑动"""
    x1 = size["width"] * 0.5  # x1 坐标
    y1 = size["height"] * 0.25  # 起点y1坐标
    y2 = size["height"] * 0.75  # 终点y2坐标
    for i in range(n):
        driver.swipe(x1, y1, x1, y2, t)


# 向左滑
def swipeLeft(driver, t=500, n=1):
    """向左屏幕滑动"""
    x1 = size["width"] * 0.75  # 起点x1坐标
    y1 = size["height"] * 0.5  # y1 坐标
    x2 = size["width"] * 0.25  # 终点x2坐标
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)


# 向右滑
def swipeRight(driver, t=500, n=1):
    """向右屏幕滑动"""
    x1 = size["width"] * 0.25  # 起点x1坐标
    y1 = size["height"] * 0.5  # y1坐标
    x2 = size["width"] * 0.75  # 终点x2坐标
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)



